<?php

	class Player
	{
		/**
		 * Constructor
		 *
		 * Tar hand om alla spelarnas attribut och skapar ett objekt för varje.
		 * Då det är ganska många olika spelarattribut så har jag valt att samla dom i en array.
		 *
		 * Exempel: $physical = array("speed" => 120, "power" => 170));
		 *
		 * För att se en tabell med alla attribut, kolla: http://code.google.com/p/onestreet/wiki/AttributesGuide
		 *
		 * @since       revision 1
		 * @version     v1
		 * @access		Public
		 * @param       array info
		 * @param       array mental
		 * @param       array physical
		 * @param       array other
		 */
		 
		public function __construct( array $info, array $mental, array $physical, array $technical )
		{
			$this->info      = $info;
			$this->mental    = $mental;
			$this->physical  = $physical;
			$this->technical = $technical;
			
			$this->mentality = round((array_sum($this->mental)) / (count($this->mental)));
			$this->physics   = round((array_sum($this->physical)) / count($this->physical));
			$this->technique = round((array_sum($this->technical)) / count($this->technical));
		}
		
		private function _calculatePersonSpeed()
		{
			if( $this->info['height'] == 150 or $this->info['height'] < 160 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(250, 350);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(350, 450);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(200, 200);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(100, 50);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(10, 10);
				elseif( $this->info['weight'] == 100 ):                               return array(1, 1);
				endif;
			
			elseif( $this->info['height'] == 160 or $this->info['height'] < 170 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(200, 300);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(350, 450);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(200, 200);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(100, 50);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(10, 10);
				elseif( $this->info['weight'] == 100 ):                               return array(2, 1);
				endif;
			
			elseif( $this->info['height'] == 170 or $this->info['height'] < 180 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(350, 400);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(250, 400);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(500, 800);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(750, 950);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(300, 500);
				elseif( $this->info['weight'] == 100 ):                               return array(150, 300);
				endif;
			
			elseif( $this->info['height'] == 180 or $this->info['height'] < 190 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(300, 300);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(350, 400);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(550, 350);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(950, 300);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(700, 150);
				elseif( $this->info['weight'] == 100 ):                               return array(300, 50);
				endif;
			
			elseif( $this->info['height'] == 190 or $this->info['height'] < 200 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(250, 50);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(350, 110);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(400, 250);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(500, 300);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(800, 310);
				elseif( $this->info['weight'] == 100 ):                               return array(400, 100);
				endif;
			
			elseif( $this->info['height'] == 200 or $this->info['height'] < 210 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(10, 10);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(50, 20);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(150, 50);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(300, 75);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(460, 150);
				elseif( $this->info['weight'] == 100 ):                               return array(550, 100);
				endif;
			
			elseif( $this->info['height'] == 210 ):
			
				if(     $this->info['weight'] == 50 or $this->info['weight'] < 60 ):  return array(1, 1);
				elseif( $this->info['weight'] == 60 or $this->info['weight'] < 70 ):  return array(30, 30);
				elseif( $this->info['weight'] == 70 or $this->info['weight'] < 80 ):  return array(180, 100);
				elseif( $this->info['weight'] == 80 or $this->info['weight'] < 90 ):  return array(200, 110);
				elseif( $this->info['weight'] == 90 or $this->info['weight'] < 100 ): return array(350, 150);
				elseif( $this->info['weight'] == 100 ):                               return array(400, 200);
				endif;
			
			endif;
			
		}
		
		/**
		 * _run
		 *
		 * Vill du få en spelare att springa, då har du hittat rätt. Med spelarens attribut (tillsammans med längd/vikt tabell) genererar vi
		 * ett snabbhetsvärde samt ett accelerationsvärde. När du anropar funktionen behöver du bara ange distans i meter.
		 *
		 * Funktionen returnerar en array med lite roliga värden - snabbhet, acceleration, tid i sekunder och topphastighet
		 * exempel: $midfielder->_run(10) - Lagets mittfältare springer 10meter
		 *
		 * @since       revision 4
		 * @version     v1
		 * @access		Public
		 * @param       distance numeric
		 * @return      array
		 */
		
		public function _run( $distance )
		{
			$personfactor = $this->_calculatePersonSpeed();
			
			$speed = ( $this->physical['strength'] + $this->physical['pace'] + $this->physical['jumping'] + $this->physical['balance'] - rand(1, 50) ) / 4;
			$speed = ( $speed + $personfactor[0] - rand(1,50) ) / 2;
			
			$acceleration = $this->physical['acceleration'] - rand(1,100);
			
			while($i < $speed) {
						
				$i += $acc;
				$acc = (($acceleration / 3.047 )+ 10);
				if( $i > $speed) $i = $speed;
				if( $i != 0 ) $steps[] = sprintf("%.2f", ($i / 27 + 5) / 3.6);
				
			}
			
			while($runned <= $distance) {
				$seconds += 1 / 1000;
				if( ceil($seconds) < count($steps) ) {
					$runned += ($steps[ceil($seconds) - 1]) / 1000;
				} else {
					$runned += ($steps[count($steps) - 1]) / 1000;
				}
			}
			
			return array("speed" => $speed, "acceleration" => $acceleration, "distance" => $distance, "time_in_seconds" => sprintf("%.2f", $seconds), "topspeed" => $steps[count($steps) - 1]);
		}
	}

?>